package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.mapper.BaseTradeMarkMapper;
import com.atguigu.gmall.product.service.BaseTradeMarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author mgx
 * @version 1.0
 * @description: TODO
 * @date 2022/10/21 0:18
 */
@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTradeMarkController {

    @Autowired
    private BaseTradeMarkService baseTradeMarkService;

    /**
     * 分页查询品牌列表
     * /admin/product/baseTrademark/{page}/{limit}
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/{page}/{limit}")
    public Result getTradeMarkPage(@PathVariable Long page,
                                   @PathVariable Long limit) {
        IPage<BaseTrademark> trademarkList = baseTradeMarkService.getTradeMarkList(page, limit);
        return Result.ok(trademarkList);
    }


    /**
     * 新增品牌
     * /admin/product/baseTrademark/save
     * @param baseTrademark
     * @return
     */
    @PostMapping("/save")
    public Result save(@RequestBody BaseTrademark baseTrademark) {
        baseTradeMarkService.save(baseTrademark);
        return Result.ok();
    }


    /**
     * 修改品牌
     * /admin/product/baseTrademark/update
     * @param baseTrademark
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody BaseTrademark baseTrademark) {
        baseTradeMarkService.updateById(baseTrademark);
        return Result.ok();
    }


    /**
     * 删除品牌
     * /admin/product/baseTrademark/remove/{id}
     * @param id
     * @return
     */
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Long id) {
        baseTradeMarkService.removeById(id);
        return Result.ok();
    }


    /**
     * 根据id获取对应的品牌属性值
     * /admin/product/baseTrademark/remove/{id}
     * @param id
     * @return
     */
    @GetMapping("/get/{id}")
    public Result get(@PathVariable Long id){
        BaseTrademark baseTrademark = baseTradeMarkService.getById(id);
        return Result.ok(baseTrademark);
    }
}
